package com.jy.wms.common.base;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.dao.WmsShipmentOrderMapper;
import com.jy.wms.pojo.SysHz;
import com.jy.wms.pojo.WmsGoods;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
import java.util.Map;

public class GoodsMapImportHanlder extends ExcelDataHandlerDefaultImpl {
    private static Logger log = LoggerFactory.getLogger(WmsGoods.class);
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        System.out.print("value:" + value);
        log.info("value:" + value);
        if (value instanceof Double) {
            NumberFormat nf = new DecimalFormat("#");
            value = nf.format(value);
        }
        if(originKey!="" && originKey!=null){
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }
}
    private String getRealKey(String originKey) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        List<SysHz> hz = (List) session.getAttribute(BaseSessionInfo.SessionConsignor);
        String hzid = null;
        if (hz.size() > 0) {
            hzid = hz.get(0).getHzid();
        }

        System.out.println("originKey:" + originKey);
        log.info("originKey:" + originKey);
        // WmsOwnerShipmentorderconfig wmsOwnerShipmentorderconfig = wmsShipmentOrderMapper.getWmsShipmentOrderConfig(hzid);

        //if (wmsOwnerShipmentorderconfig != null) {
        if (originKey.equals("货品编号")) {
            return "bh";
        }
        if (originKey.equals("货品名称")) {
            return "mc";
        }
        if (originKey.equals("补货上限")) {
            return "bhsx";
        }
        if (originKey.equals("种类名称")) {
            return "zlmc";
        }

        if (originKey.equals("货品条码")) {
            return "tm";
        }
        if (originKey.equals("包装名称")) {
            return "bzmc";
        }
        if (originKey.equals("是否不可销售")) {
            return "bkxs";
        }
        if (originKey.equals("是否采集SN码")) {
            return "cjsn";
        }
        if (originKey.equals("从存储区补货")) {
            return "ccqbh";
        }
        if (originKey.equals("NC编码")) {
            return "nc";
        }
        if (originKey.equals("补货单位")) {
            return "bhdw";
        }
        if (originKey.equals("从箱拣货补货")) {
            return "xjhwbh";
        }
        if (originKey.equals("取整方式")) {
            return "qzfs";
        }
        if(originKey.equals("质检规则名称")){
            return "zjgzmc";
        }
        if (originKey.equals("规格")) {
            return "gg";
        }
        if (originKey.equals("有效期控制")) {
            return "yxqkz";
        }
        if (originKey.equals("周期类型")) {
            return "zqlx";
        }
        if (originKey.equals("有效期")) {
            return "yxq";
        }
        if (originKey.equals("失效期预警")) {
            return "sxqyj";
        }
        if (originKey.equals("是否有配件")) {
            return "zhhp";
        }
        if (originKey.equals("配件货品编号")) {
            return "pjhpbh";
        }
        if (originKey.equals("配件数量")) {
            return "pjhpsl";
        }
        if (originKey.equals("是否存在物料清单")) {
            return "bom";
        }
        if (originKey.equals("物料货品编号")) {
            return "wlhpbh";
        }
        if (originKey.equals("物料数量")) {
            return "wlhpsl";
        }
        if (originKey.equals("拣货位主单位拣货库位类型")) {
            return "jhwzlx";
        }
        if (originKey.equals("主单位库位名称")) {
            return "zkwmc";
        }
        if (originKey.equals("拣货位内包装拣货库位类型")) {
            return "jhwnlx";
        }
        if (originKey.equals("内包装库位名称")) {
            return "nkwmc";
        }
        if (originKey.equals("拣货位箱拣货库位类型")) {
            return "jhxnlx";
        }
        if (originKey.equals("箱单位库位名称")) {
            return "xkwmc";
        }
        if (originKey.equals("供应商编号")) {
            return "gysbh";
        }
        if (originKey.equals("供应商优先级")) {
            return "gysyxj";
        }
        return "";
    }
    }